package com.heima.common.tess4j;

import lombok.Getter;
import lombok.Setter;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.awt.image.BufferedImage;

@Setter
@Getter
@ConfigurationProperties(prefix = "tess4j")
public class Tess4jClient {
    private String dataPath;
    private String language;

    public String doOCR(BufferedImage image) throws TesseractException {

        Tesseract tesseract = new Tesseract();

        tesseract.setDatapath(dataPath);

        tesseract.setLanguage(language);

        String str = tesseract.doOCR(image);

        return str.replaceAll("\\r|\\n", "-").replaceAll(" ", "-");
    }
}
